package org.linphone.activity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.linphone.LinphoneManager;
import com.leehuubsd.yiyanzb.R;
import com.umeng.analytics.MobclickAgent;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.graphics.drawable.AnimationDrawable;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.WifiLock;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.CallLog;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request.Method;
import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

public class PhoneActivity extends Activity implements OnClickListener {
	private LinearLayout system, lehu,lehuzb;
	private String phone,phonename;
	private Editor edit;
	private SharedPreferences sharedPreferences;

	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.call_phone);
		system = (LinearLayout) findViewById(R.id.system_call);
		lehu = (LinearLayout) findViewById(R.id.lehu_call);
		lehuzb = (LinearLayout) findViewById(R.id.lehu_call1);
		system.setOnClickListener(this);
		lehu.setOnClickListener(this);
		lehuzb.setOnClickListener(this);
		sharedPreferences = getSharedPreferences("bosideng",
				Context.MODE_WORLD_READABLE);
		edit = sharedPreferences.edit();
		Intent intent = this.getIntent();
		phone = intent.getStringExtra("phone");
		phonename = intent.getStringExtra("phonename");
		if (TextUtils.isEmpty(phonename)) {
			phonename = "";
		}

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.system_call:
			edit.putBoolean("call", false);
			edit.commit();
			try {
				Intent intent = new Intent();
				intent.setAction("android.intent.action.CALL");
				intent.setData(Uri.parse("tel:" + phone));
				startActivity(intent);
				finish();
			} catch (Exception e) {
				// TODO: handle exception
			}
			break;
		case R.id.lehu_call:
			Intent intentb = new Intent(PhoneActivity.this,
					CallPhoneActivity.class);
			intentb.putExtra("CALLNAME", phonename);
			intentb.putExtra("CALLNUMBER", phone);
			startActivity(intentb);
			finish();
			break;
		case R.id.lehu_call1:
			LinphoneManager.getInstance().newOutgoingCall(phone, phonename);
			finish();
			break;

		default:
			break;
		}
	}
}
